********Clean and compile data needed for analysis from MxFLS2 and MxFLS3********

*Clean MxFLS2 data
cd "$reploc/programs"
do clean_mxfls2.do
tempfile mxfls2full
save "`mxfls2full'", replace

*Clean MxFLS3 data
cd "$reploc/programs"
do clean_mxfls3.do
tempfile mxfls3full
save "`mxfls3full'", replace

*Append MxFLS2 and MxFLS3 data
use "`mxfls2full'", clear
append using "`mxfls3full'"
destring pid_link, replace
tempfile mxfls23full
save "`mxfls23full'"


*Create timelines to get precise location, migration, and birth information

cd "$reploc/programs"
do timelines_mexico.do
cd "$reploc/data/created_data"
save indiv_prov_hist_mexico, replace


*Create lifetime experienced real GDP growth mean and real GDP growth standard deviation
cd "$reploc/programs"
do growth_stats_mexico.do
cd "$reploc/data/created_data"
save indiv_provgrbir_stats_mex, replace

*Create lifetime experienced real GDP growth mean and real GDP growth standard deviation, for state of residence
cd "$reploc/programs"
do growth_stats_stateresidence_mexico.do
cd "$reploc/data/created_data"
save indiv_provgrres_stats_mex, replace

*Merge lifetime macro experiences and clean MxFLS data for analysis
cd "$reploc/programs"
do vars_mxfls.do "`mxfls23full'"
cd "$reploc/data/created_data"
save mex_full, replace
